<?php

namespace app\command\test;

use app\admin\service\user\UserService;
use app\command\BaseCommand;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use think\facade\Cache;

/**
 * 队列测试运行
 */
class QueueTestRun extends BaseCommand
{
    protected function configure()
    {
        $this->setName('QueueTestRun')
            ->addArgument('queue_name', Argument::REQUIRED, '队列名称')
            ->setDescription('消息队列测试运行,传入一个参数:队列的key值');
        $this->outputArgumentNotice();
    }

    protected function execute(Input $input, Output $output)
    {
        $queue_name = $input->getArgument('queue_name');

        $key = "{queues:$queue_name}";
        $cache_data = Cache::store('redis')->handler()->lrange($key, 0, 0);
        if (empty($cache_data[0])) {
            exit($key . ':缓存队列中没有数据');
        }

        $data = json_decode($cache_data[0], true);
        if ($queue_name == 'exportUserDataQueue') {
            $result = UserService::getUserList($data['data']['params'], true, true);
        } else {
            exit("暂未定义此 queue_name 的执行逻辑");
        }
        PE($result);
    }
}
